<?php
	/*
	 * AJAX call to save a new command in the database.
	 * Publicity messages are stored in "publicity"
	 *
	 * Variables:
	 *   type (string) 	: Command type (current: SETTINGS, SPONSOR)
	 *   rpt (int) 		: repeat timer (in minutes)
	 *   pars (string) 	: parameters for the command.
	 *
	 * Returns: xml
	 *
	 */

	$clean["command"] = "###".$_GET["type"]." ".$_GET["pars"];

	print_r($_GET);

	// Party last maximally 7 hours (maybe this should not be hard-coded...)
	if($_GET["rpt"] != 0){
		// There is a repeat, calculate how many times we can do it with this repetition delay in a 7 hours (7x60 minutes) party.
		$times = 7*60 / $_GET["rpt"];
	}else{
		$times = 1;
	}
	for($i=0;$i<$times;$i++){
		mysql_query("INSERT INTO publicity SET pubText=\"".$clean["command"]."\", pubFirstdate=DATE_ADD(\"".$_GET["frst"].":00\", INTERVAL ".($i*$_GET["rpt"])." MINUTE), pubUpdateDate=NOW(), pubIsCommand=\"1\"");
	}

	exit;
?>